/*	
 *				
 *					ISNW ---- It is a war.It is not warcraft!
 *
 *
 *					Author:					zhoukeli(haxixi_keli)
 *					Filename:				SkyBoxSceneNode.h
 *					CreateTime:				2009/01/03
 *					ModifyTime:				2009/01/03
 *
 */

#ifndef __ISNW_SKY_BOX_SCENE_NODE_H__
#define __ISNW_SKY_BOX_SCENE_NODE_H__

#include "include/ISkyBoxSceneNode.h"
#include "include/isnwMaterial.h"

namespace ISNW
{
namespace scene
{
	enum E_SKY_PLANE
	{
		E_SP_FRONT = 0,
		E_SP_BACK,
		E_SP_LEFT,
		E_SP_RIGHT,
		E_SP_TOP,
		E_SP_BOTTOM,

		E_SP_COUNT,
	};

	class SkyBoxSceneNode : public ISkyBoxSceneNode
	{
	public:
		SkyBoxSceneNode(ISceneManager* sm,ISceneNode* parent,s32 id,video::ITexture* front,video::ITexture* back,
			video::ITexture* left,video::ITexture* right,video::ITexture* top,video::ITexture* bottom,core::vector3df pos,
			core::vector3df rotate,core::vector3df scale)
			:ISkyBoxSceneNode(sm,parent,id,front,back,left,right,top,bottom,pos,rotate,scale)
		{
			Materials[E_SP_FRONT].setTexture(0,front);
			Materials[E_SP_BACK].setTexture(0,back);
			Materials[E_SP_LEFT].setTexture(0,left);
			Materials[E_SP_RIGHT].setTexture(0,right);
			Materials[E_SP_TOP].setTexture(0,top);
			Materials[E_SP_BOTTOM].setTexture(0,bottom);

			const f32 l = 5;

			// front
			Vertices[E_SP_FRONT][0] = video::vertex(-l,-l,l,0,0,-1,255,255,255,255,0,1);
			Vertices[E_SP_FRONT][1] = video::vertex(-l,l,l,0,0,-1,255,255,255,255,0,0);
			Vertices[E_SP_FRONT][2] = video::vertex(l,l,l,0,0,-1,255,255,255,255,1,0);
			Vertices[E_SP_FRONT][3] = video::vertex(l,-l,l,0,0,-1,255,255,255,255,1,1);

			Indices[E_SP_FRONT][0] = 0;
			Indices[E_SP_FRONT][1] = 1;
			Indices[E_SP_FRONT][2] = 2;
			Indices[E_SP_FRONT][3] = 0;
			Indices[E_SP_FRONT][4] = 2;
			Indices[E_SP_FRONT][5] = 3;

			// back
			Vertices[E_SP_BACK][0] = video::vertex(-l,-l,-l,0,0,1,255,255,255,255,1,1);
			Vertices[E_SP_BACK][1] = video::vertex(-l,l,-l,0,0,1,255,255,255,255,1,0);
			Vertices[E_SP_BACK][2] = video::vertex(l,l,-l,0,0,1,255,255,255,255,0,0);
			Vertices[E_SP_BACK][3] = video::vertex(l,-l,-l,0,0,1,255,255,255,255,0,1);

			Indices[E_SP_BACK][0] = 0;
			Indices[E_SP_BACK][1] = 2;
			Indices[E_SP_BACK][2] = 1;
			Indices[E_SP_BACK][3] = 0;
			Indices[E_SP_BACK][4] = 3;
			Indices[E_SP_BACK][5] = 2;

			// right
			Vertices[E_SP_RIGHT][0] = video::vertex(l,-l,l,-1,0,0,255,255,255,255,0,1);
			Vertices[E_SP_RIGHT][1] = video::vertex(l,l,l,-1,0,0,255,255,255,255,0,0);
			Vertices[E_SP_RIGHT][2] = video::vertex(l,l,-l,-1,0,0,255,255,255,255,1,0);
			Vertices[E_SP_RIGHT][3] = video::vertex(l,-l,-l,-1,0,0,255,255,255,255,1,1);

			Indices[E_SP_RIGHT][0] = 0;
			Indices[E_SP_RIGHT][1] = 1;
			Indices[E_SP_RIGHT][2] = 2;
			Indices[E_SP_RIGHT][3] = 0;
			Indices[E_SP_RIGHT][4] = 2;
			Indices[E_SP_RIGHT][5] = 3;

			// left
			Vertices[E_SP_LEFT][0] = video::vertex(-l,-l,-l,1,0,0,255,255,255,255,0,1);
			Vertices[E_SP_LEFT][1] = video::vertex(-l,l,-l,1,0,0,255,255,255,255,0,0);
			Vertices[E_SP_LEFT][2] = video::vertex(-l,l,l,1,0,0,255,255,255,255,1,0);
			Vertices[E_SP_LEFT][3] = video::vertex(-l,-l,l,1,0,0,255,255,255,255,1,1);

			Indices[E_SP_LEFT][0] = 0;
			Indices[E_SP_LEFT][1] = 1;
			Indices[E_SP_LEFT][2] = 2;
			Indices[E_SP_LEFT][3] = 0;
			Indices[E_SP_LEFT][4] = 2;
			Indices[E_SP_LEFT][5] = 3;

			// top
			Vertices[E_SP_TOP][0] = video::vertex(-l,l,l,0,-1,0,255,255,255,255,1,1);
			Vertices[E_SP_TOP][1] = video::vertex(l,l,l,0,-1,0,255,255,255,255,1,0);
			Vertices[E_SP_TOP][2] = video::vertex(l,l,-l,0,-1,0,255,255,255,255,0,0);
			Vertices[E_SP_TOP][3] = video::vertex(-l,l,-l,0,-1,0,255,255,255,255,0,1);

			Indices[E_SP_TOP][0] = 0;
			Indices[E_SP_TOP][1] = 2;
			Indices[E_SP_TOP][2] = 1;
			Indices[E_SP_TOP][3] = 0;
			Indices[E_SP_TOP][4] = 3;
			Indices[E_SP_TOP][5] = 2;

			// bottom
			Vertices[E_SP_BOTTOM][0] = video::vertex(-l,-l,-l,0,1,0,255,255,255,255,0,0);
			Vertices[E_SP_BOTTOM][1] = video::vertex(-l,-l,l,0,1,0,255,255,255,255,1,0);
			Vertices[E_SP_BOTTOM][2] = video::vertex(l,-l,l,0,1,0,255,255,255,255,1,1);
			Vertices[E_SP_BOTTOM][3] = video::vertex(l,-l,-l,0,1,0,255,255,255,255,0,1);

			Indices[E_SP_BOTTOM][0] = 0;
			Indices[E_SP_BOTTOM][1] = 1;
			Indices[E_SP_BOTTOM][2] = 2;
			Indices[E_SP_BOTTOM][3] = 0;
			Indices[E_SP_BOTTOM][4] = 2;
			Indices[E_SP_BOTTOM][5] = 3;
		}

	public:
		void render();

		void onRegisterSceneNode();

		// always visible
		core::aabbox3df getBoundBox() const
		{
			return core::aabbox3df(-999999.9f,-999999.9f,-999999.9f,999999.9f,999999.9f,999999.9f);
		}

	protected:
		video::material	Materials[E_SP_COUNT];

		video::vertex	Vertices[E_SP_COUNT][4];

		u16				Indices[E_SP_COUNT][6];
	};
} // end namespace scene
} // end namespace ISNW
#endif
